
var usename = document.querySelector('#usename');
var paseword = document.querySelector('#paseword');
var button = document.querySelector('#next');
var wrong = document.querySelector('#wronginformation')
var yx = false;
var usekey = "";
var usevalue = "";
usename.onblur = function () {
    usekey = usename.value;
}
paseword.onblur = function () {
    usevalue = paseword.value;
}
usename.oninput = function () {
    changecolor();
}
paseword.oninput = function () {
    changecolor();
}
var changecolor = function () {
    if (usename.value.length > 0 && paseword.value.length > 0) {
        yx = true;
        button.style.background = '#D13639';
    } else {
        yx = false;
        button.style.background = 'white';
    }
}

button.onclick = function () {
    if (yx) {
        if (check()) {
            var destination = addid(geturl());
            location.href =  destination;
        } else {
            wrong.innerHTML = '&nbsp;&nbsp;您的用户名或密码也许有误，或是如果您已有数月未玩游戏，' +
                '则可能需要更新为xx帐号。请参阅<a href="">无法登录</a>链接了解详情。'
        }
    }
}

function check() {
    if(!localStorage.hasOwnProperty(usename.value)){
        return false;
    }
    var arr = [];
    arr = localStorage.getItem(usename.value).split(',')
    return arr[0] == paseword.value;
}

paseword.addEventListener("keyup", function (event) {
    event.preventDefault();
    if (event.keyCode === 13) {
        button.click();
    }
});

usename.addEventListener("keyup", function (event) {
    event.preventDefault();
    if (event.keyCode === 13) {
        if (paseword.value.length > 6) {
            button.click();
        } else {
            paseword.focus();
        }
    }
});

for (var i = 0; i < localStorage.length; i++) {
    console.log(localStorage.key(i));
    // localStorage.removeItem(localStorage.key(i));
}

var abq = document.querySelector('#create');

geturl = function () {
    var url = window.location.href;
    var start = url.indexOf('from=');
    if(start==-1){
        return 'index_xbtzy.html';
    }
    var fw = "";
    // for (var i = start + 5; ; i++) {
    //     if (url.charAt(i) == '$') break;
    //     fw = fw + url.charAt(i);
    // }
    // console.log(fw);
    fw = url.substring(start + 5, url.indexOf('$'));
    return fw;
}

addid = function (fw) {
    return fw = fw + "?" + escape(usename.value) + "id$";
}

abq.href = abq.href + "?from=" + geturl() + "$";

